//
//  promotionTVCell2.m
//  UIScrollView的快速使用
//
//  Created by hongfei tam on 2019/2/27.
//  Copyright © 2019 YQ05. All rights reserved.
//

#import "promotionTVCell2.h"
#import "../MKConstant.h"

@interface promotionTVCell2()<UITextFieldDelegate>{
    BOOL isproSW1On;
    //BOOL isButtonOn;
}
@property (weak, nonatomic) IBOutlet UIImageView *titleimg2;
@property (weak, nonatomic) IBOutlet UILabel *protitle;
@property (weak, nonatomic) IBOutlet UILabel *proLabel1;
@property (weak, nonatomic) IBOutlet UITextField *proTF1;
@property (weak, nonatomic) IBOutlet UILabel *proLabel2;
@property (weak, nonatomic) IBOutlet UITextField *proTF2;
@property (weak, nonatomic) IBOutlet UILabel *proLabel3;
@property (weak, nonatomic) IBOutlet UISwitch *proSW1;
@property (weak, nonatomic) IBOutlet UILabel *proSWLabel1;
@property (weak, nonatomic) IBOutlet UILabel *proLabel4;
@property (weak, nonatomic) IBOutlet UITextField *proTF4;

@property (weak, nonatomic) IBOutlet UIButton *prosubmitBtn;


@end

@implementation promotionTVCell2

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.backgroundColor = [UIColor whiteColor];
    // Initialization code
    self.protitle.textColor = MENUBROWN;
    // Initialization code 初始化
    _protitle.font = [UIFont systemFontOfSize:22.0]; //  属性：字体 font 类名＋systemFontOfSize ＋ 字体大小编号
    
    _proLabel1.textColor = [UIColor darkGrayColor]; //内容颜色
    _proLabel1.font = [UIFont systemFontOfSize:16.0]; //  属性：字体 font 类名＋systemFontOfSize ＋ 字体大小编号
    
    [self textfield1];
    [self textfield2];
    [self textfield3];


    

    
    _proLabel2.textColor = [UIColor darkGrayColor]; //内容颜色
    _proLabel2.font = [UIFont systemFontOfSize:16.0]; //  属性：字体 font 类名＋systemFontOfSize ＋ 字体大小编号
    
    _proLabel3.textColor = [UIColor darkGrayColor]; //内容颜色
    _proLabel3.font = [UIFont systemFontOfSize:16.0]; //  属性：字体 font 类名＋systemFontOfSize ＋ 字体大小编号
    
    _proLabel4.textColor = [UIColor darkGrayColor]; //内容颜色
    _proLabel4.font = [UIFont systemFontOfSize:16.0]; //  属性：字体 font 类名＋systemFontOfSize ＋ 字体大小编号
    
    _proSWLabel1.text = @"女";
    isproSW1On = true;  //设置默认状态
    //[_proSW1 setOn:YES animated:YES];
//    [switchButton setOn:NO];
//    [switchButton addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
    
    //提交按钮
    //  作用：为Button 添加一个内容 1:title 2状态
    [_prosubmitBtn setTitle:@"提交" forState:UIControlStateNormal];
    //  作用：为Button 内容设置颜色 1:title颜色 2状态
    //  颜色：1 背景颜色backgroundColor 2 字体颜色setTitleColor
    //  颜色：默认情况：title 白色
    [_prosubmitBtn setTitleColor:MENUBROWN forState:UIControlStateNormal];
    //    button.backgroundColor = [UIColor grayColor];
    //  setBackgroundImage:背景图片设置 1 加载图片 2 状态
    [_prosubmitBtn setBackgroundImage:[UIImage imageNamed:@"botton_140x40.jpg"] forState:UIControlStateNormal];
    //  选中不放：高亮
    //[_prosubmitBtn setBackgroundImage:[UIImage imageNamed:@"2.jpg"] forState:UIControlStateHighlighted];

}

// 属性
-(void)textfield1{
//    UITextField *textfield = [[UITextField alloc]initWithFrame:CGRectMake(10, 50, 300, 30)];
//    textfield.borderStyle = UITextBorderStyleLine;// 边框
//    textfield.textColor = [UIColor redColor];// text 字体颜色 内容字体大小
//    textfield.font = [UIFont systemFontOfSize:17.0];
//    textfield.placeholder = @"please enter text";// 提示
    
    _proTF1.keyboardType = UIKeyboardTypeDefault;
//    UIKeyboardTypeDefault,                // Default type for the current input method.
//    UIKeyboardTypeASCIICapable,           // Displays a keyboard which can enter ASCII characters
//    UIKeyboardTypeNumbersAndPunctuation,  // Numbers and assorted punctuation.
//    UIKeyboardTypeURL,                    // A type optimized for URL entry (shows . / .com prominently).
//    UIKeyboardTypeNumberPad,              // A number pad with locale-appropriate digits (0-9, ۰-۹, ०-९, etc.). Suitable for PIN entry.
//    UIKeyboardTypePhonePad,               // A phone pad (1-9, *, 0, #, with letters under the numbers).
//    UIKeyboardTypeNamePhonePad,           // A type optimized for entering a person's name or phone number.
//    UIKeyboardTypeEmailAddress,           // A type optimized for multiple email address entry (shows space @ . prominently).
//    UIKeyboardTypeDecimalPad NS_ENUM_AVAILABLE_IOS(4_1),   // A number pad with a decimal point.
//    UIKeyboardTypeTwitter NS_ENUM_AVAILABLE_IOS(5_0),      // A type optimized for twitter text entry (easy access to @ #)
//    UIKeyboardTypeWebSearch NS_ENUM_AVAILABLE_IOS(7_0),    // A default keyboard type with URL-oriented addition (shows space . prominently).
//    UIKeyboardTypeASCIICapableNumberPad NS_ENUM_AVAILABLE_IOS(10_0),
    _proTF1.returnKeyType = UIReturnKeyDone;
    //设置UITextField的边框样式
    _proTF1.borderStyle = UITextBorderStyleRoundedRect;//圆角
    //    UITextBorderStyleNone, // 无边框
    //    UITextBorderStyleLine, // 有黑色边框
    //    UITextBorderStyleBezel, // 有灰色边框和阴影
    //    UITextBorderStyleRoundedRect // 圆角
    
    _proTF1.clearButtonMode = UITextFieldViewModeWhileEditing; //输入框右侧删除按钮  在UITextField文本框中开始编辑的时候显示清除设置，点击清除按钮删除内容
    _proTF1.delegate = self;// 谁来响应
}

// 属性
-(void)textfield2{
    _proTF2.keyboardType = UIKeyboardTypePhonePad;
    _proTF2.returnKeyType = UIReturnKeyDone;
    //设置UITextField的边框样式
    _proTF2.borderStyle = UITextBorderStyleRoundedRect;//圆角
    _proTF2.clearButtonMode = UITextFieldViewModeWhileEditing; //输入框右侧删除按钮  在UITextField文本框中开始编辑的时候显示清除设置，点击清除按钮删除内容
    _proTF2.delegate = self;// 谁来响应
}

// 属性
-(void)textfield3{
    _proTF4.keyboardType = UIKeyboardTypeEmailAddress;
    _proTF4.returnKeyType = UIReturnKeyDone;
    //设置UITextField的边框样式
    _proTF4.borderStyle = UITextBorderStyleRoundedRect;//圆角
    _proTF4.clearButtonMode = UITextFieldViewModeWhileEditing; //输入框右侧删除按钮  在UITextField文本框中开始编辑的时候显示清除设置，点击清除按钮删除内容
    _proTF4.delegate = self;// 谁来响应
}



// 输入完成之后被调用
-(void)textFieldDidEndEditing:(UITextField *)textField{
    NSLog(@"text=%@",textField.text);
}
// 点击done之后被调用
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    NSLog(@"tag=%ld",(long)textField.tag);
    [textField resignFirstResponder];//取消当前键盘输入响应
    return true;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
   // [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

+(instancetype)createCellWithTableView:(UITableView*)tableView{
    static NSString *ID = @"protvcell";
    promotionTVCell2 *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        // xib加载cell
        cell = [[[NSBundle mainBundle]loadNibNamed:@"promotionTVCell2" owner:nil options:nil]lastObject];
    }
    return cell;
}
-(void)loadData:(NSString*)image label:(NSString*)label andprotitledic:(NSMutableDictionary*)protitledic{
    self.titleimg2.image = [UIImage imageNamed:image];
    self.protitle.text = label;
    
    self.proLabel1.text = [protitledic valueForKey:@"Prolabel1"];
    self.proLabel2.text = [protitledic valueForKey:@"Prolabel2"];
    self.proLabel3.text = [protitledic valueForKey:@"Prolabel3"];
    self.proLabel4.text = [protitledic valueForKey:@"Prolabel4"];
}
- (IBAction)proSW1action:(id)sender {
    //isproSW1On = [_proSW1 isOn];
    NSLog(@"isproSW1On 现在的状态 %id",isproSW1On);
    isproSW1On = !isproSW1On;
    if (isproSW1On) {
        [self btmethodstatus:true];
    }else {
        [self btmethodstatus:false];
    }
}
- (IBAction)submitBtn:(id)sender {
    NSLog(@"提交信息 ");
    
//    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
//    [dic setValue:@"我来自Teacher" forKey:@"info"];
    
    NSMutableDictionary *dic = [self submitAction];
    NSLog(@"提交字典  %@",dic);
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"Promotionsend" object:nil userInfo:dic];
}

-(void)btmethodstatus:(BOOL)status{
    if (status) {
        
        NSLog(@"點擊了true ");
        _proSWLabel1.text = @"女";
        //[_proSW1 setOn:YES];
//        [mpickerView setHidden:NO];
//        [phlabel setHidden:NO];

    }else{
        NSLog(@"點擊了false ");
        _proSWLabel1.text = @"男";
     //   [_proSW1 setOn:NO];
//        [bt_method setTitleColor:MYCOLORBLUE forState:UIControlStateNormal];
//        bt_method.backgroundColor = [UIColor clearColor];
//        [switchButton setOn:NO];
//        [mpickerView setHidden:YES];
//        [phlabel setHidden:YES];
//        tf_userName.placeholder = @" 用戶名";
    }
    NSLog(@" SWstatus %id",status);
}

-(NSMutableDictionary*)submitAction{
    [_proTF1 resignFirstResponder];
    [_proTF2 resignFirstResponder];
    [_proTF4 resignFirstResponder];
    NSString *prostr1 = [_proTF1.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    NSString *prostr2 = [_proTF2.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    NSString *prostr4 = [_proTF4.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    NSString *sexstr = @"";
    if (isproSW1On) { //性别值
        sexstr = @"女";
    }else{
       sexstr = @"男";
    }
   
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setValue:prostr1 forKey:@"name"];
    [dic setValue:prostr2 forKey:@"phone"];
    [dic setValue:prostr4 forKey:@"email"];
    [dic setValue:sexstr forKey:@"sex"];
    return dic;
}
@end
